package com.springcloud.consumer.command;

import java.util.HashMap;

import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.HystrixCommand;
import com.springcloud.consumer.domain.User;

public class UserCommand extends HystrixCommand<User>{

	private RestTemplate restTemplate;
	
	private int id;
	
	public UserCommand(com.netflix.hystrix.HystrixCommand.Setter setter,RestTemplate restTemplate,int id) {
		super(setter);
		this.restTemplate = restTemplate;
		this.id = id;
	}

	@Override
	protected User run() throws Exception {
		
		//restTemplate.getForEntity("http://SERVICE-FRONTEND/hi?name={1}", String.class, "emin").getBody();

		HashMap<String, String> uriVariables = new HashMap<>();
		uriVariables.put("id", String.valueOf(id));
		return restTemplate.getForObject("http://SERVICE-FRONTEND/hello?id={id}", User.class, uriVariables);
	}

	
}
